package com.lmt_28;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;

public class TCPServer {
    public static List<Socket>onlineSocket = new ArrayList<>();
    public static void main(String[] args) throws Exception {
         ServerSocket socket = new ServerSocket(8888);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(32,4,32, TimeUnit.SECONDS,new ArrayBlockingQueue<>(8),Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());

        while (true){
            Socket accept = socket.accept();
            onlineSocket.add(accept);
            System.out.println(accept.getRemoteSocketAddress() + "上线了");
            pool.execute(new ServerThread(accept));
        }

    }
}
